package Main;
import System.Listener;

import org.eclipse.swt.widgets.Display;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.servlet.Context;
import org.mortbay.jetty.servlet.ServletHolder;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;

import com.sun.jersey.spi.container.servlet.ServletContainer;


import Control.gc;
import DataTags.DataTagsAdapter;

public class main {

	/**
	 * Initiation is done via Spring framework
	 */
	public static gc menu=null;
	public static Listener listener=null;
	public static void main(String[] args) throws Exception {
		BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource("glue.xml"));
		menu= (gc)beanFactory.getBean("gc");
		listener= (Listener)beanFactory.getBean("listen");
		listener.start();
		Display display = Display.getDefault();
		menu.sShell.open();
		ServletHolder sh=new ServletHolder(ServletContainer.class);
        sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
        sh.setInitParameter("com.sun.jersey.config.property.packages", "Web");
		Server server = new Server(8080);
		Context root = new Context(server,"/",Context.SESSIONS);
		root.addServlet(sh, "/*");

		
		
		//====start routine=======
		server.start();
		  while (!menu.sShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
			display.dispose();
			server.stop();
			System.exit(0);
		
	}

}
